package capitalizeTitle;

public class Solution {
    public String capitalizeTitle(String title) {
        String[] words = title.split(" ");
        if(words.length == 0) return "";
        for (int i = 0; i < words.length; i++) {
            if(words[i].length() <= 2) {
                char[] chars = words[i].toCharArray();
                for (int j = 0; j < chars.length; j++) {
                    chars[j] = Character.toLowerCase(chars[j]);
                }
                words[i] = new String(chars);
            }
            else {
                char[] chars = words[i].toCharArray();
                chars[0] = Character.toUpperCase(chars[0]);
                for (int j = 1; j <chars.length ; j++) {
                    chars[j] = Character.toLowerCase(chars[j]);
                }
                words[i] = new String(chars);
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append(words[0]);
        for (int i = 1; i < words.length; i++) {
            sb.append(" "+words[i]);
        }
        return sb.toString();
    }
}
